<?php

class TagLibblog extends TagLib {

    protected $tags = array(
        // 标签定义： attr 属性列表 close 是否闭合（0 或者1 默认1） alias 标签别名 level 嵌套层次  
        'sort' => array('attr' => 'name,function,outputhtml,key,item,params', 'level' => 3),
        'sked' => array('attr' => 'name,function,outputhtml,key,item,params', 'level' => 3),
        'showimg' => array('attr' => 'name,function,outputhtml,key,item,params', 'level' => 3),
        'com' => array('attr' => 'name,function,outputhtml,key,item,params', 'level' => 3)
    );

    public function _com($attr, $content) {
        $tag = $this->parseXmlAttr($attr);
        $mid = $tag['mid'];
        $str = '';
        $str .='<?php $db = D("CommentView");';
        $str .='$sort=$db->where("mid=".'. $mid . ')->order("id asc")->select();';
        $str .= 'foreach($sort as $field):?>';
        $str .=$content;
        $str .= '<?php endforeach;?>';
        return $str;
    }

    public function _sort($attr, $content) {
        $tag = $this->parseXmlAttr($attr);
        $str = '';
        $str .='<?php $db = M("sort");';
        $str .='$sort=$db->';
        $str .='select();';
        $str .= 'foreach($sort as $field):?>';
        $str .=$content;
        $str .= '<?php endforeach;?>';
        return $str;
    }

    public function _sked($attr, $content) {
        $tag = $this->parseXmlAttr($attr);
        $str .='';
        $str .='<?php $db = M("skedchpat");';
        $str .='$sort=$db->where(array("pid"=>$_SESSION["uid"]))->';
        if (isset($tag['limit'])) {
            $str .='limit(' . $tag['limit'] . ')->';
        }
        $str .= 'select();';
        $str .= 'foreach($sort as $field):?>';
        $str .=$content;
        $str .= '<?php endforeach;?>';
        return $str;
    }

    public function _showimg($attr, $content) {
        $tag = $this->parseXmlAttr($attr);
        $kid = $tag['kid'];
        $str .='';
        $str .='<?php $db = M("img");';
        $str .='$sort=$db->where(array("sid"=>' . $kid . '))->limit(9)->select();';
        $str .= 'foreach($sort as $field):?>';
        $str .=$content;
        $str .= '<?php endforeach;?>';
        return $str;
    }

}

?>
